package com.xdk.templatescala.service.impl;

import com.xdk.templatescala.common.enums.ScaleStatusEnum;
import com.xdk.templatescala.dao.ScaleAnswerDao;
import com.xdk.templatescala.model.ScaleAnswerEntry;
import com.xdk.templatescala.service.ScaleAnswerService;
import com.xdk.templatescala.utils.DateUtils;
import com.xdk.templatescala.utils.uuid.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
@Slf4j
public class ScaleAnswerServiceImpl implements ScaleAnswerService {

    @Autowired
    private ScaleAnswerDao scaleAnswerDao;


    @Override
    public List<ScaleAnswerEntry> findScaleAnswerEntryByParam() {
        return scaleAnswerDao.findAll();
    }

    @Override
    public List<ScaleAnswerEntry> addScaleAnswerEntry(List<ScaleAnswerEntry> scaleAnswerEntries) {
        for (ScaleAnswerEntry scaleAnswerEntry : scaleAnswerEntries){
            scaleAnswerEntry.setAnswerId(IdUtils.fastSimpleUUID());
            scaleAnswerEntry.setStatus(ScaleStatusEnum.SCALE_STATUS_1.getCode());
            scaleAnswerEntry.setCreateTime(DateUtils.getTime());
            scaleAnswerEntry.setUpdateTime(DateUtils.getTime());
            scaleAnswerDao.addScaleAnswerEntry(scaleAnswerEntry);
        }
        return scaleAnswerEntries;
    }

    @Override
    public ScaleAnswerEntry findOne(String scaleAnswerId) {
        return scaleAnswerDao.findOne(scaleAnswerId);
    }

    @Override
    public List<ScaleAnswerEntry> findAllById(String scaleAnswerIds) {
        return scaleAnswerDao.findAllById(Arrays.asList(scaleAnswerIds.split(",")));
    }
}
